home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / STACK.CPP < prev    next >
Text File  |  1997-05-06  |  815b  |  47 lines

  1.  #include <stack>
  2.  #include <vector>
  3.  #include <deque>
  4.  #include <string>
  5.  
  6.  using namespace std;
  7.  
  8.  int main ()
  9.  {
  10.    //
  11.    // Make a stack using a vector container.
  12.    //
  13.    stack<int,vector<int> > s;
  14.    //
  15.    // Push a couple of values on the stack.
  16.    //
  17.    s.push(1);
  18.    s.push(2);
  19.    cout << s.top() << endl;
  20.    //
  21.    // Now pop them off.
  22.    //
  23.    s.pop();
  24.    cout << s.top() << endl;
  25.    s.pop();
  26.    //
  27.    // Make a stack of strings using a deque.
  28.    //
  29.    stack<string,deque<string> > ss;
  30.    //
  31.    // Push a bunch of strings on then pop them off.
  32.    //
  33.    int i;
  34.    for (i = 0; i < 10; i++)
  35.    {
  36.      ss.push(string(i+1,'a'));
  37.      cout << ss.top() << endl;
  38.    }
  39.    for (i = 0; i < 10; i++)
  40.    {
  41.      cout << ss.top() << endl;
  42.      ss.pop();
  43.    }
  44.  
  45.    return 0;
  46.  }
  47.